package com.spukmk2me.spukmk2mesceneeditor.gui;

import java.awt.Frame;
import javax.swing.DefaultListModel;
import javax.swing.JDialog;

import com.spukmk2me.resource.IResource;
import com.spukmk2me.resource.ResourceSet;

public class FontDialog extends JDialog
{
    public FontDialog( ResourceSet manager, Frame parent, boolean modal )
    {
        super( parent, modal );
        initComponents();
        m_resourceSet = manager;
        Reload();
    }

    private void Reload()
    {
        DefaultListModel model = (DefaultListModel)m_fontList.getModel();
        int n = m_resourceSet.GetNumberOfResources( IResource.RT_BITMAPFONT );

        model.clear();

        for ( int i = 0; i != n; ++i )
        {
            model.addElement( m_resourceSet.GetResource(
                i, IResource.RT_BITMAPFONT ).GetProxyName() );
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        m_fontList = new javax.swing.JList();
        m_addButton = new javax.swing.JButton();
        m_closeButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Fonts");

        jLabel1.setText("Fonts:");

        m_fontList.setModel( new DefaultListModel() );
        jScrollPane1.setViewportView(m_fontList);

        m_addButton.setText("Add");
        m_addButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                m_addButtonActionPerformed(evt);
            }
        });

        m_closeButton.setText("Close");
        m_closeButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                m_closeButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 158, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(m_closeButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(m_addButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 77, Short.MAX_VALUE))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(m_addButton))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(m_closeButton)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void m_closeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_m_closeButtonActionPerformed

        this.dispose();
    }//GEN-LAST:event_m_closeButtonActionPerformed

    private void m_addButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_m_addButtonActionPerformed

        FontDialog_Add dlg = new FontDialog_Add( m_resourceSet,
            (Frame)this.getOwner(), true );

        dlg.setVisible( true );
        Reload();
    }//GEN-LAST:event_m_addButtonActionPerformed

    private ResourceSet m_resourceSet;

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton m_addButton;
    private javax.swing.JButton m_closeButton;
    private javax.swing.JList m_fontList;
    // End of variables declaration//GEN-END:variables
}
